#include <string>
#include <iostream>
#include <cmath>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include "guni.h"
#include "recursos.h"

using namespace std;
  
c_guni::c_guni(string no, int c, int al, int d, int b, int m, int v,int nu, int nd, string * de,TTF_Font * f)
{
 desc = new SDL_Surface*[nd];
 ndesc = nd;
 
 SDL_Color colorfuente;
 colorfuente.r = 0; colorfuente.g = 0; colorfuente.b = 0;

 for(int i = 0;i < nd;i++)
 {
  char * a = stringachar(de[i]);
  desc[i] = TTF_RenderText_Blended(f,a,colorfuente);
  delete a;
 }
 
 char campo[100]; 
 
 char * a;
 a = stringachar(no);
 nom = TTF_RenderText_Blended(f,a,colorfuente); 
 delete a;
 
 //c = c * (int)pow((double)2,(double)n);
 a = intachar(c); 
 strcpy(campo,"Coste: ");
 strcat(campo,a);
 coste = TTF_RenderText_Blended(f,campo,colorfuente); 
 delete a;
 a = intachar(al); 
 strcpy(campo,"Alcance: ");
 strcat(campo,a);
 alc = TTF_RenderText_Blended(f,campo,colorfuente); 
 delete a;
 a = intachar(d); 
 strcpy(campo,"Dano: ");
 strcat(campo,a);
 dan = TTF_RenderText_Blended(f,campo,colorfuente); 
 delete a;
 a = intachar(b); 
 strcpy(campo,"Blindaje: ");
 strcat(campo,a);
 blin = TTF_RenderText_Blended(f,campo,colorfuente); 
 delete a;
 a = intachar(m); 
 strcpy(campo,"Movimiento: ");
 strcat(campo,a);
 mov = TTF_RenderText_Blended(f,campo,colorfuente); 
 delete a;
 a = intachar(v); 
 strcpy(campo,"PV: ");
 strcat(campo,a);
 vid = TTF_RenderText_Blended(f,campo,colorfuente); 
 delete a;
 a = intachar(nu); 
 strcpy(campo,"Disponibles: ");
 strcat(campo,a);
 num = TTF_RenderText_Blended(f,campo,colorfuente); 
 delete a;
}
c_guni::~c_guni()
{
 for(unsigned int i = 0;i < ndesc;i++)
  SDL_FreeSurface(desc[i]);
 
 delete desc;
 
 SDL_FreeSurface(nom);
 SDL_FreeSurface(coste);
 SDL_FreeSurface(alc);
 SDL_FreeSurface(dan);
 SDL_FreeSurface(blin);
 SDL_FreeSurface(mov);
 SDL_FreeSurface(vid);
 SDL_FreeSurface(num);
}
